package net.bblot.lottery.api.request;

import android.content.Context;
import android.os.Handler;

import net.bblot.lottery.api.ApiResponseListener;
import net.bblot.lottery.api.task.HttpTask;
import net.bblot.lottery.util.AppConfig;
import net.bblot.lottery.util.Md5Utils;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by feng on 2017/8/30.
 */

public class GetKey {
    public static HttpTask getKey(Context context, ApiResponseListener listener) {
        String url = "http://a.91zbl.cn:8080" + "/api?m=system.AppInfo.getAesKey";

        String terminalId = "2";
        String version = AppConfig.getCurrentAppVersion(context);
        String time = System.currentTimeMillis() + "";
        String sign = Md5Utils.getMD5(terminalId + version + time + Md5Utils.getMD5("ae3815ed5ca2e89c36d13615c8306d31"));

        List<NameValuePair> queryParams = new ArrayList<NameValuePair>();
        queryParams.add(new BasicNameValuePair("terminal_id", terminalId));
        queryParams.add(new BasicNameValuePair("version", version));
        queryParams.add(new BasicNameValuePair("time", time));
        queryParams.add(new BasicNameValuePair("sign", sign));

        final Handler handler = HttpTask.getHttpHandler(listener);
        return HttpTask.getTask(handler, context, url, HttpTask.HTTP_REQEST_TYPE_GET, queryParams, null, null, null);

    }
}
